<template>
  <div class="user">
    <el-main>
      <el-row type="flex" justify="space-between">
        <el-col :span="18">
          <el-button v-if="rid == 0" type="primary" @click="clickCreat">
            创建用户
          </el-button>
          <el-select v-model="type" clearable placeholder="请选择用户类型" @change="changeVal">
            <el-option v-for="item in RoleAll" :key="item.id" :label="item.role_name" :value="item.id" />
          </el-select>
          <el-input v-model="search" clearable style="width: 300px; margin-left: 15px" placeholder="搜索公司、联系人"
            class="input-with-select" @clear="clear" @keyup.enter.native="searchVal">
            <el-button slot="append" style="background-color: #45a321; color: #fff; border-radius: 0"
              @click="searchVal">
              搜索
            </el-button>
            <i slot="prefix-icon" class="el-icon-search" />
          </el-input>
        </el-col>
        <el-col :span="6" style="display: flex; justify-content: flex-end">
          <el-button type="primary" @click="clickExport">
            导出推送数据
          </el-button>
          <el-button type="primary" @click="clickExportUser">
            导出用户数据
          </el-button>
        </el-col>
      </el-row>

      <el-table align="center" :data="UserItem" border style="width: 100%; margin: 20px 0" @row-click="rowClick">
        <el-table-column align="center" prop="id" label="用户ID" width="80" />
        <el-table-column align="center" label="公司名称" width="220">
          <template slot-scope="scope">
            <!-- <router-link @click.stop="setToken(item.token)">{{scope.row.company}}</router-link> -->
            <a class="ck" @click.stop="setToken(scope.row.token)">{{
              scope.row.company
            }}</a>
          </template>
        </el-table-column>
        <el-table-column v-if="rid == 0" align="center" prop="role" label="账号类型" />
        <el-table-column align="center" label="营业执照">
          <template slot-scope="scope">
            <span v-if="scope.row.type == '1' && scope.row.business" class="ck"
              @click="clickbusiness(scope.row)">查看</span>
            <p v-if="rid == 0">
              <span v-if="scope.row.type == '1' && !scope.row.business" class="upload"
                @click="clickbusiness(scope.row)">上传</span>
            </p>
            <span v-if="scope.row.type == '2'" :class="scope.row.type == '2' ? 'ck' : ''"
              @click="clickbusiness(scope.row)">查看</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="数量">
          <template slot-scope="scope">
            {{ scope.row.is_data == 0 ? "数据初始中" : scope.row.num }}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="over_on" label="有效期" />
        <el-table-column align="center" prop="username" label="联系人" />
        <el-table-column align="center" prop="mobile" label="电话" />
        <el-table-column align="center" prop="create_on" label="创建时间" />
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button class="ck" type="text" @click.stop="setToken(scope.row.token)">
              查看
            </el-button>
            <el-button v-if="rid == 0" class="editText" type="text" @click="clickEdit(scope.row.id)">
              修改
            </el-button>
            <el-button v-if="rid == 0" class="deletText" type="text" @click="deletUser(scope.row.id)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background :current-page="Number(page.page)" :page-size="page.size"
          layout="total, prev, pager, next, jumper" :total="parseInt(page.count)" align="left"
          @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>
    </el-main>
    <el-dialog :destroy-on-close="false" :close-on-click-modal="false" title="创建用户" :visible.sync="dialogVisible"
      width="40%" center @close="closeDialog">
      <el-steps :active="active">
        <el-step title="步骤 1" description="填写用户信息" icon="iconfont icon-1-yonghuguanli" />
        <el-step title="步骤 2" description="设置专利主体" icon="iconfont icon-2-shenqingguanli" />
        <el-step title="步骤 3" description="设置企业画像" icon="iconfont icon-5-xiaoxituisong" />
      </el-steps>
      <el-row v-if="active == 1">
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 公司名称</el-col>
          <el-col :xl="18">
            <el-input v-model="creat.company" placeholder="请输入公司名称" />
          </el-col>
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 账号有效期</el-col>
          <el-col :xl="18">
            <el-select v-model="creat.validity_date" style="width: 100%" placeholder="请选择账号有效期">
              <el-option v-for="item in options.expire" :key="item" :label="item" :value="item" />
            </el-select>
          </el-col>
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 账号类型</el-col>
          <el-col :xl="18">
            <!-- <el-select style="width: 100%;" v-model="creat.CreatType" placeholder="请选择用户类型">
              <el-option
               v-for="item in Role"
               :key="item.id"
               :label="item.role_name"
               :value="item.id">
              </el-option>
            </el-select> -->
            <el-select v-model="creat.CreatType" style="width: 100%" multiple filterable allow-create
              default-first-option placeholder="请选择用户类型">
              <el-option v-for="item in Role" :key="item.id" :label="item.role_name" :value="item.id" />
            </el-select>
          </el-col>
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 联系人姓名</el-col>
          <el-col :xl="6">
            <el-input v-model="creat.username" placeholder="请输入联系人姓名" />
          </el-col>
          <el-col :xl="3" :push="3"> 联系人职位</el-col>
          <el-col :xl="6" :push="3">
            <el-input v-model="creat.position" placeholder="请输入联系人职位" />
          </el-col>
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 联系人手机号</el-col>
          <el-col :xl="6">
            <el-input v-model="creat.mobile" placeholder="请输入联系人手机号" />
          </el-col>
          <el-col :xl="3" :push="3"> 联系人邮箱</el-col>
          <el-col :xl="6" :push="3">
            <el-input v-model="creat.email" placeholder="请输入联系人邮箱" />
          </el-col>
        </el-col>
      </el-row>
      <el-row v-if="active == 2">
        <el-col class="creat_mr" :xl="24">
          <el-input v-model="creat.company" disabled placeholder="请输入公司名称" />
        </el-col>
        <el-col v-for="(item, index) in crt" :key="index" class="creat_mr" :xl="24">
          <el-input v-model="crt[index].cr" placeholder="请输入公司名称" />
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-button type="primary" class="pubBtn3" @click="addCompany">
            添加
          </el-button>
        </el-col>
      </el-row>
      <el-row v-if="active == 3">
        <el-col class="creat_mr" :xl="24"> 设置业务关键词</el-col>
        <el-col style="margin-bottom: 10px" :xl="24">
          <el-tag v-for="(tag, index) in creat.sales_key" style="margin-right: 15px; margin-bottom: 15px" closable
            @close="handleClose(tag)" @click="clickTag(index)">
            {{ tag }}
          </el-tag>
        </el-col>
        <el-col class="" :xl="24">
          <el-input v-model="creat.tagVal" placeholder="请输入业务关键词" />
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-button class="pubBtn3" type="primary" @click="clickAddTag">
            添加
          </el-button>
        </el-col>
        <el-col class="creat_mr" :xl="24"> 设置运营关键词</el-col>
        <el-col :xl="24">
          <el-tag v-for="(tags, indexs) in options.operate_key" style="margin-right: 25px" :effect="tags.effect"
            :type="tags.type" @click="activeTag(indexs)">
            {{ tags.name }}
          </el-tag>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="active < 2" type="button" class="pubBtn2" @click="dialogVisible = false">取消操作</el-button>
        <el-button v-if="active > 1" type="button" class="pubBtn2" @click="perv">上一步</el-button>
        <el-button v-if="active == 1" type="button" class="pubBtn" @click="next">保存，下一步</el-button>
        <el-button v-if="active == 2" type="button" class="pubBtn" @click="next2">保存，下一步</el-button>
        <el-button v-if="active >= 3" type="button" class="pubBtn" @click="submit">保存,创建用户</el-button>
      </span>
    </el-dialog>

    <el-dialog :destroy-on-close="true" :close-on-click-modal="false" title="修改用户" :visible.sync="editVisible"
      width="40%" center @close="closeDialog2">
      <el-row>
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 公司名称</el-col>
          <el-col :xl="18">
            <el-input v-model="edit.company" disabled placeholder="请输入公司名称" />
          </el-col>
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 账号有效期</el-col>
          <el-col :xl="18">
            <el-select v-model="edit.validity_date" style="width: 100%" placeholder="请选择账号有效期">
              <el-option v-for="item in options.expire" :key="item" :label="item" :value="item" />
            </el-select>
          </el-col>
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 账号类型</el-col>
          <el-col :xl="18">
            <el-select v-model="creat.CreatType" style="width: 100%" multiple filterable allow-create
              default-first-option placeholder="普通账户">
              <el-option v-for="item in Role" :key="item.id" :label="item.role_name" :value="item.id" />
            </el-select>
            <!--      <el-select style="width: 100%;" v-model="edit.type" placeholder="普通账户">
              <el-option
               v-for="item in Role"
               :key="item.id"
               :label="item.role_name"
               :value="item.id">
              </el-option>
            </el-select> -->
          </el-col>
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 联系人姓名</el-col>
          <el-col :xl="6">
            <el-input v-model="edit.username" placeholder="请输入联系人姓名" />
          </el-col>
          <el-col :xl="3" :push="3"> 联系人职位</el-col>
          <el-col :xl="6" :push="3">
            <el-input v-model="edit.position" placeholder="请输入联系人职位" />
          </el-col>
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-col :xl="3"> 联系人手机号</el-col>
          <el-col :xl="6">
            <el-input v-model="edit.mobile" placeholder="请输入联系人手机号" />
          </el-col>
          <el-col :xl="3" :push="3"> 联系人邮箱</el-col>
          <el-col :xl="6" :push="3">
            <el-input v-model="edit.email" placeholder="请输入联系人邮箱" />
          </el-col>
        </el-col>
      </el-row>
      <el-row>
        <p class="context" style="
            border-top: 1px solid #e7eaf0;
            padding: 20px 0;
            margin-top: 30px;
            font-weight: 600;
          ">
          输入该公司专利主体名称
        </p>
        <el-col class="creat_mr" :xl="24">
          <el-input v-model="edit.company" disabled />
        </el-col>
        <el-col v-for="(item, index) in eidt_show" :key="index" class="creat_mr" :xl="24">
          <el-input v-if="item.cr" v-model="item.cr" />
        </el-col>
        <el-col v-for="(item, index2) in crt" class="creat_mr" :xl="24">
          <el-input v-model="crt[index2].cr" placeholder="请输入公司名称" />
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-button type="primary" class="pubBtn3" @click="editCompany">
            添加
          </el-button>
        </el-col>
      </el-row>
      <el-row>
        <p class="context" style="
            border-top: 1px solid #e7eaf0;
            padding: 20px 0;
            margin-top: 30px;
            font-weight: 600;
          ">
          设置业务关键词
        </p>
        <!-- <el-col class="creat_mr" :xl="24">设置业务关键词</el-col> -->
        <el-col v-if="edit.sales_key != ''" style="margin-bottom: 10px" :xl="24">
          <el-tag v-for="(tag, index) in edit.sales_key" style="margin-right: 15px; margin-bottom: 15px" closable
            @close="edithandleClose(tag)" @click="editclickTag(index)">
            {{ tag }}
          </el-tag>
        </el-col>
        <el-col class="" :xl="24">
          <el-input v-model="edit.tagVal" placeholder="请输入业务关键词" />
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <el-button class="pubBtn3" type="primary" @click="editAddTag">
            添加
          </el-button>
        </el-col>
        <el-col class="creat_mr" :xl="24">
          <p class="context" style="
              border-top: 1px solid #e7eaf0;
              margin-top: 30px;
              font-weight: 600;
            ">
            设置运营关键词
          </p>
        </el-col>
        <el-col :xl="24">
          <el-tag v-for="(tag, index) in options.operate_key" :key="tag.name"
            style="margin-right: 25px; cursor: pointer" :effect="tag.effect" :type="tag.type"
            @click="editactiveTag(index)">
            {{ tag.name }}
          </el-tag>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="button" class="pubBtn2" @click="closeDialog2">取消操作</el-button>
        <el-button type="button" class="pubBtn" @click="editSave">保存修改</el-button>
      </span>
    </el-dialog>
    <License :item="businessInfo" :license-visible="licenseVisible" @cancle="cancleLice" />

    <ExportUser :export-visible="exportVisible" :role="RoleAll" @Determine="Determine" />
    <ExportUserIndex :export-user-status="ExportUserStatus" :role="RoleAll" @DetermineUsr="DetermineUsr" />
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getToken, setToken, removeToken } from "@/utils/auth";
import {
  userIndex,
  CreateUserIndex,
  UserCreate,
  UserEdit,
  UserDetail,
  UserDelete,
  getRole,
  getRoleAll,
  createStep1,
  createStep2,
  userExport,
} from "@/api/admin";
import License from "@/components/License";
import ExportUser from "@/components/ExportUser";
import ExportUserIndex from "@/components/ExportUserIndex";

export default {
  components: {
    License,
    ExportUser,
    ExportUserIndex,
  },
  data() {
    return {
      input3: 0,
      eidt_show: [],
      crt: [],
      ExportUserStatus: false,
      creat: {
        creatCompany: "",
        company: "",
        username: "",
        position: "",
        mobile: "",
        email: "",
        CreatType: [],
        validity_date: "",
        patent_body: [],
        sales_key: [],
        operate_key: [],
        tagVal: "",
      },
      edit: {
        creatCompany: "",
        company: "",
        username: "",
        position: "",
        mobile: "",
        email: "",
        type: [],
        validity_date: "",
        patent_body: [],
        sales_key: [],
        operate_key: [],
        tagVal: "",
      },
      type: '',
      search: "",
      effect: "plain",
      active: 1,
      editVisible: false,
      dialogVisible: false,
      exportVisible: false,
      options: [],
      tableData: [],
      UserItem: [],
      editId: null,
      businessInfo: [],
      licenseVisible: false,
      page: [],
      Role: [],
      RoleAll: [],
    };
  },
  computed: {
    ...mapGetters([
      "sidebar",
      "avatar",
      "name",
      "roles",
      // "type",
      "is_admin_view",
      "rid",
    ]),
  },
  async mounted() {
    const page = sessionStorage.getItem("page");
    if (this.$route.query.rid) {
      this.type = Number(this.$route.query.rid);
    }
    this.getUser(page ? page : undefined);
    this.getRoleData();
    if (this.$route.query.v && this.$route.query.id) {
      this.edit = await UserDetail({
        id: this.$route.query.id,
      });
      // this.editVisible = true;
      this.editId = this.$route.query.id;
    }
  },
  methods: {
    test(value) {
      // console.log(this.page, value);
      setToken(value);
    },
    Determine() {
      this.exportVisible = false;
    },
    DetermineUsr() {
      this.ExportUserStatus = false;
    },
    async getUser(page = undefined) {
      const params = {
        keywords: this.search,
        type: this.type,
      };
      try {
        const resUser = await userIndex(page ? { page, ...params } : params);

        this.UserItem = resUser.list;
        const res = await CreateUserIndex();
        this.options = res;
        this.page = resUser.page;
      } catch (e) {
        this.$message.error(e.message);
      }
    },
    async getRoleData() {
      try {
        this.Role = await getRole();
        this.RoleAll = await getRoleAll();

      } catch (e) {
        this.$message.error(e.message);
      }
    },
    async searchVal() {
      this.getUser();
    },
    //每页下拉显示数据
    async handleSizeChange(size) {
      try {
        const resUser = await userIndex({
          keywords: this.search,
          type: this.type,
          page: size,
        });
        this.UserItem = resUser.list;
        const res = await CreateUserIndex();
        this.options = res;
        this.page = resUser.page;
        sessionStorage.setItem("page", this.page.page);
      } catch (e) {
        this.$message.error(e.message);
      }
    },

    //点击第几页
    async handleCurrentChange(currentPage) {
      sessionStorage.setItem("page", currentPage);
      try {
        const resUser = await userIndex({
          keywords: this.search,
          type: this.type,
          page: Number(currentPage),
        });
        this.UserItem = resUser.list;
        const res = await CreateUserIndex();
        this.options = res;
        this.page = resUser.page;
      } catch (e) {
        this.$message.error(e.message);
      }
    },
    clickCreat() {
      this.dialogVisible = true;
    },
    clickExport() {
      this.exportVisible = true;
    },
    clickExportUser() {
      this.ExportUserStatus = true;
    },
    async next() {
      try {
        await createStep1({
          company: this.creat.company,
          validity_date: this.creat.validity_date,
          type: this.creat.CreatType,
          username: this.creat.username,
          position: this.creat.position,
          mobile: this.creat.mobile,
          email: this.creat.email,
          patent_body: this.creat.patent_body,
          sales_key: this.creat.sales_key,
          operate_key: this.creat.operate_key,
        });
        if (this.active++ >= 3) this.active = 1;
      } catch (error) {
        this.$message.error(error.message);
      }
      // if(!this.creat.company){
      //   this.$message.error("请填写公司名称")
      //   return;
      // }
      // if(!this.creat.validity_date){
      //   this.$message.error("请选择账号有效期")
      //   return;
      // }
      // if(!this.creat.CreatType){
      //   this.$message.error("请选择账号类型")
      //   return;
      // }
      // if(!this.creat.username){
      //   this.$message.error("请输入联系人姓名")
      //   return;
      // }
      // if(!this.creat.position){
      //   this.$message.error("请输入联系人职位")
      //   return;
      // }
      // if(!this.creat.mobile){
      //   this.$message.error("请输入联系人手机号")
      //   return;
      // }
      // if(!this.creat.email){
      //   this.$message.error("请输入联系人邮箱")
      //   return;
      // }
      // if(this.sales_key){
      //   this.$message.error("请填写公司名称")
      //   return;
      // }
      // if(this.operate_key){
      //   this.$message.error("请填写公司名称")
      // }
    },
    async next2() {
      try {
        if (this.creat.company) {
          let arr = [];
          let arr2 = [];
          arr2.push(this.creat.company);
          this.crt.map((item) => {
            arr.push(item.cr);
          });
          this.creat.patent_body = arr2.concat(arr);
        }
        await createStep2({
          patent_body: this.creat.patent_body,
          type: this.creat.CreatType,
        });
        if (this.active++ >= 3) this.active = 1;
      } catch (error) {
        this.$message.error(error.message);
      }
    },
    clickTag(index) {
      if (this.options.operate_key[index].type) {
        this.creat.operate_key.push(this.options.operate_key[index].id);
      } else {
        this.creat.operate_key.splice(
          this.creat.operate_key.indexOf(this.options.operate_key[index].id),
          1
        );
      }
    },
    editclickTag(index) {
      if (this.options.operate_key[index].type) {
        this.edit.operate_key.push(this.options.operate_key[index].id);
      } else {
        this.edit.operate_key.splice(
          this.edit.operate_key.indexOf(this.options.operate_key[index].id),
          1
        );
      }
    },
    activeTag(index) {
      if (this.options.operate_key[index].type) {
        this.options.operate_key[index].type = "";
        this.options.operate_key[index].effect = "dark";
      } else {
        this.options.operate_key[index].type = "warning";
        this.options.operate_key[index].effect = "plain";
        this.creat.operate_key.splice(
          this.creat.operate_key.indexOf(this.options.operate_key[index].id),
          1
        );
      }
    },
    editactiveTag(index) {
      if (this.options.operate_key[index].type) {
        this.options.operate_key[index].type = "";
        this.options.operate_key[index].effect = "dark";
        this.edit.operate_key.push(this.options.operate_key[index].id);
      } else {
        this.options.operate_key[index].type = "warning";
        this.options.operate_key[index].effect = "plain";
        this.edit.operate_key.splice(
          this.edit.operate_key.indexOf(this.options.operate_key[index].id),
          1
        );
      }
    },
    companyTag(index) {
      if (
        this.creat.patent_body.indexOf(this.options.patent_body[index].id) == -1
      ) {
        this.creat.patent_body.push(this.options.patent_body[index].id);
      } else {
        this.creat.patent_body.splice(
          this.creat.patent_body.indexOf(this.options.patent_body[index].id),
          1
        );
      }
    },
    editcompanyTag(index) {
      if (
        this.edit.patent_body.indexOf(this.options.patent_body[index].id) == -1
      ) {
        this.edit.patent_body.push(this.options.patent_body[index].id);
      } else {
        this.edit.patent_body.splice(
          this.edit.patent_body.indexOf(this.options.patent_body[index].id),
          1
        );
      }
    },

    perv() {
      if (this.active == 3) {
        this.active = 2;
      } else if ((this.active = 2)) {
        this.active = 1;
      }
    },
    async submit() {
      try {
        await UserCreate({
          company: this.creat.company,
          validity_date: this.creat.validity_date,
          type: this.creat.CreatType,
          username: this.creat.username,
          position: this.creat.position,
          mobile: this.creat.mobile,
          email: this.creat.email,
          patent_body: this.creat.patent_body,
          sales_key: this.creat.sales_key,
          operate_key: this.creat.operate_key,
        });
        this.getUser();
        this.dialogVisible = false;
        this.crt = [];
        this.creat = {
          creatCompany: "",
          company: "",
          username: "",
          position: "",
          mobile: "",
          email: "",
          CreatType: [],
          validity_date: "",
          patent_body: [],
          sales_key: [],
          operate_key: [],
          tagVal: "",
        };
        this.active = 1;
        this.$message.success("保存成功");
        this.creat.CreatType = [];
      } catch (e) {
        this.crt = [];
        this.$message.error(e.message);
      }
    },
    async editSave() {
      // console.log(this.creat.CreatType);
      let arr = [];
      let arr2 = [];
      let arr3 = [];
      arr2.push(this.edit.company);
      this.crt.map((item) => {
        arr.push(item.cr);
      });
      this.eidt_show.map((item) => {
        if (item.cr) {
          arr3.push(item.cr);
        }
      });
      this.edit.patent_body = arr2.concat(arr, arr3);
      this.editVisible = false;
      try {
        await UserEdit({
          id: this.editId,
          company: this.edit.company,
          validity_date: this.edit.validity_date,
          type: this.creat.CreatType ? this.creat.CreatType : this.edit.type,
          username: this.edit.username,
          position: this.edit.position,
          mobile: this.edit.mobile,
          email: this.edit.email,
          patent_body: this.edit.patent_body,
          sales_key: this.edit.sales_key,
          operate_key: this.edit.operate_key,
        });
        this.getUser();
        this.crt = [];
        this.creat.CreatType = [];
        this.$message.success("修改成功");
      } catch (e) {
        this.crt = [];
        this.$message.error(e.message);
      }
    },

    clickAddTag() {
      if (this.creat.tagVal) {
        this.creat.sales_key.push(this.creat.tagVal);
        this.creat.tagVal = "";
      } else {
        this.$message.error("请输入业务关键词");
      }
    },
    editAddTag() {
      if (this.edit.tagVal) {
        this.edit.sales_key.push(this.edit.tagVal);
        this.edit.tagVal = "";
      } else {
        this.$message.error("请输入业务关键词");
      }
    },
    handleClose(tag) {
      this.creat.sales_key.splice(this.creat.sales_key.indexOf(tag), 1);
    },
    edithandleClose(tag) {
      this.edit.sales_key.splice(this.edit.sales_key.indexOf(tag), 1);
    },
    addCompany() {
      this.crt.push({ cr: "" });
      // if(this.input3 < 3){
      //   this.input3++;
      // }else{
      //   this.$message.error("最大添加3个")
      // }
    },
    editCompany() {
      this.crt.push({ cr: "" });
      // console.log(this.edit.company)
      // if(this.edit.company){
      //   if(this.input3 < parseInt(2-this.eidt_show.length) ){
      //     this.input3++;
      //   }else{
      //     this.$message.error("最大添加3个")
      //   }
      // }else{
      //   this.$message.error("请输入公司名称")
      // }
    },
    CloseCompany(tag) {
      this.creat.patent_body.splice(this.creat.patent_body.indexOf(tag), 1);
    },
    editCloseCompany(tag) {
      this.edit.patent_body.splice(this.edit.patent_body.indexOf(tag), 1);
    },

    async clickEdit(id) {
      try {
        this.editId = id;
        const res = await UserDetail({ id: id });
        this.editVisible = true;
        this.edit = res;
        // this.creat.CreatType.push(res.role);
        this.edit.type = res.type;
        this.eidt_show = res.patent_body;
        // this.input3 = parseInt(res.patent_body.length)
      } catch (e) {
        this.$message.error(e.message);
      }
    },
    rowClick(row) {
    },
    deletUser(id) {
      this.$confirm("是否删除该用户?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await UserDelete({ id: id });
          this.getUser();
          this.$message.success("删除成功");
        })
        .catch(() => {
          // console.log("取消");
        });
    },
    clickbusiness(item) {
      this.businessInfo = item;
      this.licenseVisible = true;
    },
    cancleLice(val) {
      this.licenseVisible = false;
      this.getUser();
    },
    changeVal(val) {
      this.getUser();
    },
    clear() {
      this.getUser();
    },
    closeDialog() {
      this.creat.CreatType = [];
    },
    closeDialog2() {
      this.creat.CreatType = [];
      this.editVisible = false;
    },
    setToken(token) {
      const news = this.$router.resolve({ path: "/#/home" });
      window.location.href = news.location.path;
      // getToken()
      sessionStorage.setItem("tokens", getToken());
      // sessionStorage.setItem("token",token)
      setToken(token);
    },
  },
};
</script>

<style scoped>
.pagination {
  margin: 15px 0;
}

.el-pagination {
  text-align: right;
}

.creat_mr {
  margin: 15px 0 10px 0;
  line-height: 40px;
}
</style>

<style>
@media (max-width: 1680px) {
  .user .el-col-push-3 {
    left: 0;
  }
}
</style>
